package uw.illno.test;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import uw.illno.dao.AdministratorDao;
import uw.illno.pojo.Student;

import java.io.InputStream;
import java.util.List;

public class testmybatis {

    @Test
    public void run() throws Exception {
        InputStream in = Resources.getResourceAsStream("sql.xml");

        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);

        SqlSession session = factory.openSession();

        AdministratorDao dao=session.getMapper(AdministratorDao.class);
        List<Student> list = dao.findallStudent();
        for (Student student: list ) {
            System.out.println(student);
        }


        Student student=new Student();
        student.setSno("test");
        int result=dao.resetpwd(student);
        if (result>0)
            System.out.println("重置密码成功");
        session.commit();
        session.close();
        in.close();
    }
}
